package obecto.task
{
	import flash.events.EventDispatcher;
	
	import obecto.event.TaskEvent;
	import obecto.event.TaskEventKind;

	public class BaseTask extends EventDispatcher implements ITask
	{
		protected var _running : Boolean = false;
		
		public function BaseTask()
		{
			super();
		}

		public function start() : void
		{
			if(running == false)
			{
				_running = true;
				
				startActual();
				
				dispatchEvent(new TaskEvent(TaskEvent.START, TaskEventKind.NONE));
			}
		}
		
		virtual protected function startActual() : void
		{
		}
		
		protected function complete() : void
		{
			_running = false;
			
			dispatchEvent(new TaskEvent(TaskEvent.COMPLETE, TaskEventKind.END));
		}
		
		public function get running() : Boolean
		{
			return _running;
		}		
	}
}